package com.muyu.controller;

import com.muyu.api.entity.ResponseEntity;
import com.muyu.api.response.ResultResponse;
import com.muyu.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName: UserController
 * @Author: Zirun.Xin
 * @Date: 2025/4/9 下午4:01
 * @Version: 1.0
 * @Description: 用户控制层
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/api/v1/user")
public class UserController {

    /**
     * 用户业务层
     */
    private final UserService userService;

    /***
     * excel批量导入用户
     * @param file excel导入文件
     * @return 响应结果集
     */
    @GetMapping(value = "/import")
    public ResponseEntity<ResultResponse<Boolean>> importUsers(@RequestParam(value = "file") MultipartFile file) {
        return ResponseEntity.ok(ResultResponse.ok(userService.importUsers(file)));
    }

    /**
     * excel批量导出用户
     *
     * @param response servlet响应
     */
    @GetMapping(value = "/export")
    public void exportUsers(HttpServletResponse response) {
        userService.exportUsers(response);
    }

    /**
     * excel批量导出用户（携带图片版）
     *
     * @param response servlet响应
     */
    @GetMapping(value = "/export-pic")
    public void exportUsersToExcel(HttpServletResponse response) {
        userService.exportUsersToExcel(response);
    }

    /**
     * word文档导出到一个模板中
     *
     * @param response servlet响应
     */
    @GetMapping(value = "/export-word-all")
    public void exportUsersToWordAll(HttpServletResponse response) {
        userService.exportUsersToWordAll(response);
    }

    /**
     * word文档导出
     *
     * @param response servlet响应
     */
    @GetMapping(value = "/export-word")
    public void exportUsersToWord(HttpServletResponse response) {
        userService.exportUsersToWord(response);
    }

    /**
     * excel多sheet导入
     *
     * @param file excel文件
     */
    @GetMapping(value = "/import-for-sheets")
    public void importForSheetUsers(@RequestParam(value = "file") MultipartFile file) {
        userService.importForSheetUsers(file);
    }

    /**
     * excel多sheet导出
     *
     * @param response servlet响应
     */
    @GetMapping(value = "/export-for-sheets")
    public void exportForSheetUsers(HttpServletResponse response) {
        userService.exportForSheetUsers(response);
    }

    /**
     * 导出pdf文件
     *
     * @param response servlet响应
     */
    @GetMapping("/export-for-pdf")
    public void exportPdfUsers(HttpServletResponse response) {
        userService.exportPdfUsers(response);
    }
}
